function hideElement(ele)
{
    document.getElementById(ele).style.visibility = 'hidden';
}

function getElementHeight(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}

function getElementWidth(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
		    xPos = elem.offsetWidth;
		}
		return xPos;
	}
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}



var current = 0;
var current_2 = 0;
var IsChild = false;
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }
  
  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

    function flyDiv(e,cat_id)
    {
        document.getElementById('div_fly_3').style.visibility = "hidden";
        var news_count = document.getElementById("news_count_"+cat_id).value;
        var cat_count = document.getElementById("cat_count_"+cat_id).value;
        if(cat_count == 0 && news_count == 0) 
        {
            current = 0;
            return;
        }
    
        var offsetfromcursorX = -4;
        var offsetfromcursorY = 0;
        var offsetdivfrompointerX = 0;
        var offsetdivfrompointerY = 0;
    
        var ie = document.all;
        var ns6 = document.getElementById && ! document.all;
    
        var curX = (ns6) ? e.pageX : e.offsetLeft;
        var curY = (ns6) ? e.pageY : e.offsetTop;
        
        curX = findPosX(e);
        curY = findPosY(e);
        
        var width = e.offsetParent.offsetWidth;

        var divFly = document.getElementById("divFly_"+cat_id);
        var div_fly_1 = document.getElementById('div_fly_1');
        
        div_fly_1.innerHTML = divFly.innerHTML;
        div_fly_1.style.left = curX + offsetfromcursorX - offsetdivfrompointerX + width + "px" ;
        div_fly_1.style.top = curY + offsetfromcursorY  + offsetdivfrompointerY  + "px";
        
        //if(!is_ie6)        
            div_fly_1.style.visibility = "visible";
        //else
        //{
        //Popup.show('div_fly_1');
        
        /*
            var oPopBody_1 = oPopup_1.document.body;
            
            oPopBody_1.style.backgroundColor = "#eff0de";
	        oPopBody_1.style.border = "1px solid #b8c1ca";
	        //oPopBody_1.style = div_fly_1.style;
	        
            oPopBody_1.innerHTML = div_fly_1.innerHTML;
            //document.write(oPopBody_1.innerHTML);
            //oPopBody_1.onmouseover = function()
            //{
                //alert("Super Man");
            //}
            
            oPopup_1.show(curX + offsetfromcursorX - offsetdivfrompointerX + width, curY + offsetfromcursorY  + offsetdivfrompointerY,getElementWidth("div_fly_1"),getElementHeight("div_fly_1"), document.body);
            */
        //}
        
        //var oPopBody_1 = oPopup_1.document.body;
        //oPopBody_1.innerHTML = "Pham Cong Son";
        //oPopup_1.show(curX + offsetfromcursorX - offsetdivfrompointerX + width, curY + offsetfromcursorY  + offsetdivfrompointerY,getElementWidth("div_fly_1"),getElementHeight("div_fly_1"), document.body);
        
        current = cat_id;
    }
    
    function dontFlyDiv(ele,cat_id)
    {        
        var divFly = document.getElementById("divFly_"+cat_id);
        divFly.style.visibility = "hidden";        
    }
    
    function move_out()
    {
        if(current == 0) return;        
        var div_fly_1 = document.getElementById('div_fly_1');
        div_fly_1.style.visibility = "hidden";
    }
    
    function showDiv()
    {
        if(current == 0) return;
         var div_fly_1 = document.getElementById('div_fly_1');
         div_fly_1.style.visibility = "visible";         
         document.getElementById('div_fly_3').style.visibility = "hidden";
    }
    
    function hideDiv()
    {
        if(current == 0) return;
        var div_fly_2 = document.getElementById('div_fly_2');
        var div_fly_1 = document.getElementById('div_fly_1');
        div_fly_1.style.visibility = "hidden";
    }
    
    function flyDiv_2_hide(e,cat_id)
    {   
        var divFly = document.getElementById("flyDiv_"+cat_id);
        document.getElementById('div_fly_2').style.visibility = "hidden";
    }
    function flyDiv_2(e,cat_id)
    {        
        
        if(document.getElementById('news_count_2_'+cat_id).value == '0')
        {            
            document.getElementById('div_fly_2').style.visibility = "hidden";
            document.getElementById('div_fly_3').style.visibility = "hidden";
            return;
        }
        
        var offsetfromcursorX = -4;
        var offsetfromcursorY = 0;
        var offsetdivfrompointerX = 0;
        var offsetdivfrompointerY = 0;
    
        var ie = document.all;
        var ns6 = document.getElementById && ! document.all;
    
        var curX = (ns6) ? e.pageX : e.offsetLeft;
        var curY = (ns6) ? e.pageY : e.offsetTop;
        
        curX = findPosX(e);
        curY = findPosY(e);        
        var width = e.offsetParent.offsetWidth ;
        
        var divFly = document.getElementById("flyDiv_"+cat_id);
        divFly.style.left = curX + offsetfromcursorX - offsetdivfrompointerX + width + 200 + "px" ;        
        divFly.style.top = curY + offsetfromcursorY  + offsetdivfrompointerY  + "px";
        
        var divTemp ;
        if(IsChild == true)
        {
            divTemp = document.getElementById('div_fly_3');
        }
        else
        {
            divTemp = document.getElementById('div_fly_2');
        }
        divTemp.style.left = curX + offsetfromcursorX - offsetdivfrompointerX + width  + "px" ;
        divTemp.style.top = curY + offsetfromcursorY  + offsetdivfrompointerY + 1  + "px";
        
        divTemp.innerHTML = divFly.innerHTML;
        divTemp.style.visibility = "visible";
        current_2 = cat_id;
    }
    
   
    
    document.onmousemove = function()
    {
        var div_fly_1 = document.getElementById('div_fly_1');
        var div_fly_2 = document.getElementById('div_fly_2');
        if(IsChild == false)
        {
            if(div_fly_1.style.visibility == "hidden" && div_fly_2.style.visibility == "visible") 
            {
                div_fly_2.style.visibility = "hidden";
            }
        }
    }
    
    function RedirectCat(cat_id)
    {
        window.location = 'TestMenu.aspx?Cat_ID='+cat_id;
    }
    

